package com.zxl.grocery.microservice.auth.server.controller;

import com.zxl.grocery.microservice.auth.server.service.ClientService;
import com.zxl.grocery.microservice.common.msg.ObjectRestResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: zxl
 * @Description: 服务与服务之间的鉴权
 * @Date: Created in 9:44 2017/10/15
 * @Modified By:
 */
@RestController
@RequestMapping("client")
public class ClientController {
    @Autowired
    private ClientService clientService;

    /**
     * @Author: Lzx
     * @Description: 申请token
     * @Params:  * @param null
     * @Date: 9:46 2017/10/15
     */
    @RequestMapping(value = "/token", method = RequestMethod.POST)
    public ObjectRestResponse getAccessToken(String clientId, String secret) throws Exception {
        return new ObjectRestResponse<String>().data(clientService.apply(clientId, secret));
    }

    /**
     * @Author: Lzx
     * @Description: 获取授权的客户端列表
     * @Params:  * @param null
     * @Date: 9:46 2017/10/15
     */
    @RequestMapping(value = "/myClient")
    public ObjectRestResponse getAllowedClient(String serviceId, String secret) {
        return new ObjectRestResponse<List<String>>().data(clientService.getAllowedClient(serviceId, secret));
    }

}
